class Solution
{
public:
    int minimizeXor(int num1, int num2)
    {
        // int oneCount1 = __builtin_popcount(num1);
        int originNum1 = num1;
        int oneCount2 = __builtin_popcount(num2);
        cout << oneCount2 << endl;
        vector<int> bits(32, 0);
        for (int i = 0; i < 32; ++i)
        {
            bits[i] = num1 & 1;
            num1 = num1 >> 1;
        }

        for (int i = 31; i >= 0; --i)
        {
            if (oneCount2 == 0)
            {
                break;
            }
            if (bits[i] == 1)
            {
                bits[i] = -1;
                --oneCount2;
            }
        }

        int i = 0;
        while (oneCount2)
        {
            if (bits[i] == 0)
            {
                bits[i] = 1;
                --oneCount2;
            }
            ++i;
        }

        int minResult = 0;
        for (int i = 31; i >= 0; --i)
        {
            minResult *= 2;
            if (bits[i] == 1)
            {
                minResult += 1;
            }
        }
        cout << minResult;
        return minResult ^ originNum1;
    }
};